<?php

namespace App\Model;

use Illuminate\Support\Facades\DB;

class UserRegisterLog extends BaseModel
{
    protected $table = 'user_register_log';
    public $timestamps = false;
    protected $connection = 'api';


    public function getRegister($channel_id)
    {
        $where['channel_id'] = $channel_id;
        $beginToday = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
        $endToday = mktime(0, 0, 0, date('m'), date('d') + 1, date('Y')) - 1;
        $where[] = ['time', '>=', $beginToday];
        $where[] = ['time', '<=', $endToday];
        $res = DB::connection($this->connection)->table($this->table)->where($where)
            ->select(
                'user_id'
            )
            ->get();
       return $this->objToArray($res);
    }

    public function getRecharge($channel_id)
    {
        $where['channel_id'] = $channel_id;
        $where['status'] = 1;
        $beginToday = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
        $endToday = mktime(0, 0, 0, date('m'), date('d') + 1, date('Y')) - 1;
        $where[] = ['pay_timestamp', '>=', $beginToday];
        $where[] = ['pay_timestamp', '<=', $endToday];
        $res = DB::connection($this->connection)->table('finance_recharge_order')->where($where)
            ->select(
                'user_id',
                DB::raw('sum(price) as sum_price')
            )
            ->groupBy('user_id')
            ->get();
        return $this->objToArray($res);
        
    }
}
